package com.example.bili.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.bili.R;
import com.example.bili.allbean.recommendedBean;
import com.example.bili.view.activity.DetailsActivity_av;
import com.facebook.drawee.view.SimpleDraweeView;

import java.util.List;

/**
 * Created by Administrator on 2017/3/10.
 */

class recommended_itemrecyAdapter extends RecyclerView.Adapter<recommended_itemrecyAdapter.VHolder> {
    private Context context;
    private List<recommendedBean.ResultBean.BodyBean> body;

    public recommended_itemrecyAdapter(Context context, List<recommendedBean.ResultBean.BodyBean> body) {
        this.context = context;
        this.body = body;
    }

    @Override
    public VHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.item_rmitem_recy, null);
        return new VHolder(view);
    }

    @Override
    public void onBindViewHolder(VHolder holder, final int position) {
        holder.simpledraweeview.setImageURI(body.get(position).getCover());
        holder.name.setText(body.get(position).getTitle());
        if (body.get(position).getStyle().equals("gm_live")) {
            String param1 = body.get(position).getParam();
            int param = Integer.parseInt(param1);
            if (param > 9999) {
                String param2 = param1.substring(0, 1);
                String param3 = param1.substring(1, 3);
                holder.bnum.setText(param2 + "." + param3 + "万");
            } else {
                holder.bnum.setText(param1);
            }
        } else {
            holder.bnum.setText(body.get(position).getPlay());
        }
        holder.pnum.setText(body.get(position).getDanmaku());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String go = body.get(position).getGotoX();
                if (go.equals("av")) {
                    context.startActivity(new Intent(context, DetailsActivity_av.class).putExtra("avid", body.get(position).getParam()));
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return body.size();
    }

    public class VHolder extends RecyclerView.ViewHolder {
        SimpleDraweeView simpledraweeview;
        TextView name;
        TextView bnum;
        TextView pnum;

        public VHolder(View itemView) {
            super(itemView);
            simpledraweeview = (SimpleDraweeView) itemView.findViewById(R.id.d_rm_recyitem_img);
            name = (TextView) itemView.findViewById(R.id.d_rm_recyitem_name);
            bnum = (TextView) itemView.findViewById(R.id.d_rm_recyitem_bnum);
            pnum = (TextView) itemView.findViewById(R.id.d_rm_recyitem_pnum);
        }
    }
}
